<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use App\Traits\Upload;


////		接口地址:
////		{{host}} = http://newp.juming.com:9696
////
////		公共参数:
////		每个接口请求都需要附带以下公共参数.
////		appid:您的APPID
////time:请求时间戳
////key: 校验KEY,加密算法: md5(您的APPKEY."&".$time)
////
////返回说明:
////code=1 操作成功，如果不等于1，则返回错误信息
///
class APIController extends Controller {
	private function options() {
		$host   = 'http://newp.juming.com:9696';
		$appid  = '123';
		$appkey = '123';
		//$time    = time();
		$time    = $this->getMillisecond();
		$options = [
			'host'   => $host,
			'appid'  => $appid,
			'appkey' => $appkey,
			'time'   => $time,
			'key'    => md5( $appkey . '&' . $time ),
		];

		return $options;
	}

	private function getMillisecond() {
		//13位时间戳
		list( $t1, $t2 ) = explode( ' ', microtime() );

		return (string) sprintf( '%.0f', ( floatval( $t1 ) + floatval( $t2 ) ) * 1000 );
	}


	public function test( Request $request ) {
		$options   = $this->options();
		$parameter = '?appid=' . $options['appid'] . '&time=' . $options['time'] . '&key=' . $options['key'];
		//查询域名
		$url = '/newapi/domain_info';
		$url = $options['host'] . $url . $parameter;

	//	dd( $options );
		$data = [
			'form_params' => [
				'ym' => 'baidu.com',
			],
		];

//		$data =[
//			'multipart' => [
//				[
//					'name'     => 'field_name',
//					'contents' => 'abc'
//				],
////				[
////					'name'     => 'file_name',
////					'contents' => fopen('/path/to/file', 'r')
////				],
//				[
//					'name'     => 'other_file',
//					'contents' => 'hello',
//					'filename' => 'filename.txt',
//					'headers'  => [
//						'X-Foo' => 'this is an extra header to include'
//					]
//				]
//			]];


		$http     = new  Client();
		$response = $http->request( 'POST', $url, $data );
		$res      = json_decode( $response->getBody() );
		dd( $res );
		//dd(	$res['code'] );

	}

    public function String_replace() {
        //  $text = '.net.cn,.org.cn,.cn,.cc,.tv,.com.cn,.net,.vip,.com,.top,.org,省级,.jl.cn,.xz.cn,.sc.cn,.hi.cn,.gz.cn,.nx.cn,.jx.cn,.cq.cn,.tw.cn,.sx.cn,.tj.cn,.js.cn,.gs.cn,.fj.cn,.sd.cn,.sn.cn,.gd.cn,.he.cn,.sh.cn,.ha.cn,.hb.cn,.xj.cn,.ln.cn,.ah.cn,.hk.cn,.hn.cn,.gx.cn,.zj.cn,.bj.cn,.qh.cn,.nm.cn,.ac.cn,.hl.cn,.yn.cn,.mo.cn';
        //    $text = '      ok,        clientHold,        serverHold,        addPeriod,        clientDeleteProhibited,        serverDeleteProhibited,        clientUpdateProhibited,        serverUpdateProhibited,        clientTransferProhibited,        serverTransferProhibited,        pendingVerification,        inactive,        clientRenewProhibited,        serverRenewProhibited,        pendingTransfer,        redemptionPeriod,        pendingDelete';
        //   $text = 'detele,pre,sna-pre,jm-pre,xw-pre,name-pre,netcn-pre,other-pre,bz-pre,gd-pre,xb-pre,drop-pre';
      //  $text = '国防机构 ,政府机关 ,事业单位 ,企业 ,个人 ,社会团体 ,民办非企业单位 ,民办非企业,基金会 ,律师执业机构 ,外国在华文化中心 ,群众性团体组织 ,司法鉴定机构 ,宗教团体 ,外国机构 ,其他(--)';
        $text = '北京市,天津市,河北省,山西省,内蒙古自治区,辽宁省,吉林省,黑龙江省,上海市,江苏省,浙江省,安徽省,福建省,江西省,山东省,河南省,湖北省,湖南省,广东省,广西壮族自治区,海南省,四川省,贵州省,云南省,重庆市,西藏自治区,陕西省,甘肃省,青海省,宁夏回族自治区,新疆维吾尔自治区';
        $text =explode(',',$text);
        $data = [];
        foreach ($text as $item ){
            $temp = str_replace(',','',$item);
            $temp = str_replace(' ','',$temp);
            $temp = trim($temp);
            $data[]= '<option value="'.$temp.'">'.$temp.'</option>';

            // echo  '<option value="'.$temp.'">'.$temp.'</option>' .PHP_EOL;
        }
        sort($data);
        //  dd($data);
        echo '<select>';
        foreach($data as $item)
        {

            echo $item;
        }
        echo '</select>';
        die;
	}
}
